package org.hong.monkey.broadcast

import org.hong.monkey.MonkeyConf
import org.hong.monkey.annotation.DeveloperApi

import scala.reflect.ClassTag

/**
 * :: DeveloperApi ::
 * An interface for all the broadcast implementations in Monkey (to allow
 * multiple broadcast implementations). MonkeyContext uses a user-specified
 * BroadcastFactory implementation to instantiate a particular broadcast for the
 * entire Monkey job.
 */
@DeveloperApi
trait BroadcastFactory {

  def initialize(isDriver: Boolean, conf: MonkeyConf): Unit

  /**
   * Creates a new broadcast variable.
   *
   * @param value value to broadcast
   * @param isLocal whether we are in local mode (single JVM process)
   * @param id unique id representing this broadcast variable
   */
  def newBroadcast[T: ClassTag](value: T, isLocal: Boolean, id: Long): Broadcast[T]

  def unbroadcast(id: Long, removeFromDriver: Boolean, blocking: Boolean): Unit

  def stop(): Unit
}
